"""author: tlf
   data: 2020/11/3
   project: ldj
"""
import IPy
import subprocess
try:
    x = input("输入要检查的网段、子网掩码:")
    ips = IPy.IP(x)
    try:
        for ip in ips:
            retcode = subprocess.call("ping ip",shell=True)
            if retcode == 0:
                print(f"{ip}可用")
            else:
                raise subprocess.CalledProcessError(f"{ip}已被使用")
    except subprocess.CalledProcessError as cpe:
        print(cpe)
except ValueError as ve:
    print("value error:",ve)

# x = input("输入要检查的网段、子网掩码:")
# ips = IPy.IP(x)
# for ip in ips:
#     print(ip)